package com.qiyi.player.base.uuid
{
   import flash.events.EventDispatcher;
   import com.qiyi.player.base.logging.ILogger;
   import flash.utils.Dictionary;
   import flash.net.SharedObject;
   import com.qiyi.player.base.utils.MD5;
   import flash.utils.getTimer;
   import com.qiyi.player.base.logging.Log;
   
   public class BaseUUID extends EventDispatcher implements IUUID
   {
      
      public function BaseUUID(param1:String, param2:String) {
         this._log = Log.getLogger("com.qiyi.player.base.uuid.BaseUUID");
         this._map = new Dictionary();
         super();
         this._name = param1;
         this._cookie = param2;
      }
      
      protected var _log:ILogger;
      
      protected var _name:String;
      
      protected var _uuid:String;
      
      protected var _isNewUser:Boolean = false;
      
      protected var _webEventId:String = "";
      
      private var _videoEventID:String = "";
      
      private var _map:Dictionary;
      
      private var _cookie:String;
      
      public function load(param1:String = "") : void {
         var so:SharedObject = null;
         var var_3:String = param1;
         try
         {
            so = SharedObject.getLocal(this._cookie,"/");
            this._uuid = so.data.uuid;
            if(this._uuid == null || !(this._uuid.length == 32))
            {
               if(so.data.serverID)
               {
                  so.data.uuid = so.data.serverID;
               }
               else if(so.data.sid)
               {
                  so.data.uuid = so.data.sid;
               }
               else if(so.data.clientID)
               {
                  so.data.uuid = so.data.clientID;
               }
               
               
               this._uuid = so.data.uuid;
               if((this._uuid) && this._uuid.length == 32)
               {
                  so.flush();
               }
               else
               {
                  this._uuid = "";
               }
            }
            if(this._uuid.length == 32)
            {
               this._log.info("success to read " + this._name);
            }
         }
         catch(e:Error)
         {
            _log.warn("failed to read " + _name + ": " + e.errorID);
            _uuid = "";
         }
      }
      
      public function save() : void {
         var so:SharedObject = null;
         try
         {
            so = SharedObject.getLocal(this._cookie,"/");
            so.data.uuid = this._uuid;
            so.flush();
            this._log.info(this._name + " : success to save ");
         }
         catch(e:Error)
         {
            _log.warn("failed to save " + _name + ": " + e.errorID);
         }
      }
      
      public function get uuid() : String {
         return this._uuid;
      }
      
      public function buildVideoEventID() : void {
         this._videoEventID = MD5.calculate(this._uuid + getTimer() + Math.random());
      }
      
      public function getVideoEventID(param1:String = "") : String {
         return this._videoEventID;
      }
      
      public function get isNewUser() : Boolean {
         return this._isNewUser;
      }
      
      public function set isNewUser(param1:Boolean) : void {
         this._isNewUser = param1;
      }
      
      public function setWebEventID(param1:String) : void {
         this._webEventId = param1;
      }
      
      public function getWebEventID() : String {
         return this._webEventId;
      }
   }
}
